<template>
  <div>
    <MainFrame menuIndex="MemberList">
      <div slot='content'>
        <div class="top-title">
          学员信息详情
        </div>
        <div class="top-button">
          <el-button type="primary" @click="back">返回</el-button>
        </div>
        <ttForm v-model="form"></ttForm>
      </div>
    </MainFrame>
  </div>
</template>
<script>
import MainFrame from '@/components/MainFrame'
import utils from '../ttJs/utils.js'
import ttForm from '@/tt_components/ttForm'
export default {
  components: {
    MainFrame,
    ttForm
  },
  data() {
    var validator = (rule, value, callback) => {
      callback();
    };
    return {
      type: null,
      form: {
        id: null,
        url: '/ay/editor/submitMember',
        items: [
          { name: 'no', value: '', label: '编号', placeholder: '请输入编号', type: 'input', rules: true, msg: '编号不能为空' }, // 0
          { name: 'image', value: '', imgUrl: '', label: '头像', type: 'img', url: '/api/upload', index: 1, limit: 1 }, // 1
          { name: 'name', value: '', label: '姓名', placeholder: '请输入姓名', type: 'input', rules: true, msg: '姓名不能为空' }, // 2
          { name: 'age', value: '', label: '年龄', placeholder: '请输入年龄', type: 'input' }, // 3
          { name: 'birth', value: '', label: '出生日期', placeholder: '请输入出生日期', type: 'input' }, // 4
          { name: 'idcard', value: '', label: '身份证号', placeholder: '请输入身份证号', type: 'input' }, // 5
          { name: 'jiguan', value: '', label: '籍贯', placeholder: '请输入籍贯', type: 'input' }, // 6
          { name: 'degree', value: '', label: '学历', placeholder: '请输入学历', type: 'input' }, // 7
          { name: 'liveAddress', value: '', label: '现居地', placeholder: '请输入现居地', type: 'input' }, // 8
          { name: 'channel', value: '', label: '来源', placeholder: '请输入来源', type: 'input' }, // 9
          { name: 'type', value: '', label: '类别', placeholder: '请输入类别', type: 'input' }, // 10
          { name: 'cert', value: '', label: '证书', placeholder: '请输入证书', type: 'input' }, // 11
          { name: 'contact', value: '', label: '联系方式', placeholder: '请输入联系方式', type: 'input' }, // 12
          { name: 'desc', value: '', label: '评价', placeholder: '请输入评价', type: 'input' }, // 13
          { name: 'images', list: [], label: '工作/生活照', type: 'images', url: '/api/upload', index: 14, multiple: false }, // 14
          { name: 'height', value: '', label: '身高', placeholder: '请输入身高', type: 'input' }, // 15
          { name: 'weight', value: '', label: '体重', placeholder: '请输入体重', type: 'input' }, // 16
          { name: 'content', value: '', label: '工作经历', placeholder: '请输入工作经历', type: 'input' }, // 17
          /*{ name: 'train', value: '', label: '培训经历', placeholder: '请输入培训经历', type: 'input' }, // 0*/
          { name: 'title', value: '', label: '专业职称', placeholder: '请输入专业职称', type: 'input' }, // 18
          { name: 'sort', value: '99999', label: '排序', placeholder: '请输入排序', type: 'input' }, // 19
          { name: 'salary', value: '', label: '薪资', placeholder: '请输入薪资', type: 'input' }, // 20
          { name: 'cover', value: '', imgUrl: '', label: '封面', type: 'img', url: '/api/upload', index: 21, limit: 1 }, // 21
          { name: 'tags', value: '', label: '标签', placeholder: '请输入标签，用分号隔开', type: 'input' }, // 22
          { name: 'constellation', value: '', label: '星座', placeholder: '请输入星座', type: 'input' } // 23
        ],
        rules: {
          no: [{ required: true, validator: validator, trigger: 'blur' }],
          name: [{ required: true, validator: validator, trigger: 'blur' }]
        }
      },
    };
  },
  mounted: function() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      var self = this;
      var id = self.$route.query.id
      self.type = self.$route.query.type
      if (utils.validateData(id)) {
        self.form.id = id;
        var url = '/ay/editor/member';
        var params = { id: id }
        var success = function(response) {
          var info = response.info;
          var items = self.form.items
          for (var index in items) {
            for (var key in info) {
              if (items[index].name == key) {
                if (items[index].type == 'img') {
                  if (utils.validateData(info[key])) {
                    items[index].imgUrl = info[key];
                  }
                }
                if (items[index].type == 'images') {
                  if (utils.validateData(info[key])) {
                    var images = info[key].split(';')
                    for (var i in images) {
                      if (utils.validateData(images[i])) {
                        var filename = images[i].substring(images[i].lastIndexOf('/') + 1, images[i].indexOf('?') > 0 ? images[i].indexOf('?') : images[i].length );
                        var image = {
                          name: filename,
                          url: images[i]
                        }
                        items[index].list.push(image)
                      }
                    }
                  }
                }
                items[index].value = info[key]
              }
            }
          }
        }
        var fail = function() {
          utils.fail('加载失败')
        }
        var complete = function() {}
        utils.requestLoading(url, params, success, fail, complete)
      }
    },
    back() {
      window.history.back();
    }
  }
};

</script>
<style scoped rel="stylesheet/scss" lang="scss">
.top-title {
  margin: 0 0 20px 150px;
  font-size: 18px;
  font-weight: bold;
}

.top-button {
  margin: 0 0 20px 150px;
}

</style>
